package org.cytoscape.myapp.cytoscape_app_v1.internal.visual;

import java.awt.Color;
import java.awt.Paint;
import java.util.List;

import org.cytoscape.myapp.cytoscape_app_v1.internal.helpers.ModelUtils;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.vizmap.VisualMappingFunction;
import org.cytoscape.view.vizmap.mappings.BoundaryRangeValues;
import org.cytoscape.view.vizmap.mappings.ContinuousMapping;

public class MappingFunctionContinuousColor implements MappingFunction{

	private String nameAttribute;
	private VisualInstanceDependecies dependecies;
	private VisualProperty<Paint> property;
	private Class<?> type;
	
	public String getNameAttribute() {
		return nameAttribute;
	}

	public void setNameAttribute(String nameAttribute) {
		this.nameAttribute = nameAttribute;
	}
	
	
	public MappingFunctionContinuousColor(String nameAttribute,
													VisualInstanceDependecies dependecies, 
													VisualProperty<Paint> property,
													Class<?> type) {
		super();
		this.nameAttribute = nameAttribute;
		this.dependecies = dependecies;
		this.property = property;
		this.type = type;
	}

	public VisualMappingFunction<?, ?> createVisualMappingFunction() {
		ContinuousMapping mapping = (ContinuousMapping)
				dependecies.getVmfFactoryC().createVisualMappingFunction(this.nameAttribute, type, property);
		
		List<Double> sortValues = ModelUtils.getColumnValueSortedEdge(dependecies.getApplicationManager().getCurrentNetwork(), this.nameAttribute);
		
		Double val1 = sortValues.get(2);
		Double val2 = sortValues.get(sortValues.size()-2);
		
		BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.BLUE, Color.BLUE, Color.BLUE);
		BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(Color.RED, Color.RED, Color.RED);
		
		mapping.addPoint(val1, brv1);
		mapping.addPoint(val2, brv2);
		
		return mapping;
		
	}


}
